#define _CRT_SECURE_NO_WARNINGS 
class Partition {
public:
    ListNode* partition(ListNode* pHead, int x)
    {
        struct ListNode* Ltail, * Lhead, * Ghead, * Gtail;
        Lhead = Ltail = (struct ListNode*)malloc(sizeof(struct ListNode));
        Ghead = Gtail = (struct ListNode*)malloc(sizeof(struct ListNode));
        Gtail->next = Ltail->next = NULL;
        struct ListNode* cur = pHead;
        while (cur)
        {
            if (cur->val < x)
            {
                Ltail->next = cur;
                Ltail = Ltail->next;
            }
            else
            {
                Gtail->next = cur;
                Gtail = Gtail->next;
            }
            cur = cur->next;
        }
        Ltail->next = Ghead->next;
        Gtail->next = NULL;
        pHead = Lhead->next;
        free(Ghead);
        free(Lhead);
        return pHead;
        // write code he
    }
};